﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SampleExamLinqXml
{
    class Statistics : IComparable<Statistics>
    {
        private string name;
        private int? wins;
        private int? loses;
        private int? draws;
        private string scores;
        private int? points;

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public int? Wins
        {
            get
            {
                return wins;
            }
            set
            {
                wins = value;
            }
        }

        public int? Loses
        {
            get
            {
                return loses;
            }
            set
            {
                loses = value;
            }
        }

        public int? Draws
        {
            get
            {
                return draws;
            }
            set
            {
                draws = value;
            }
        }

        public string Scores
        {
            get
            {
                return scores;
            }
            set
            {
                scores = value;
            }
        }

        public int? Points
        {
            get
            {
                return points;
            }
            set
            {
                points = value;
            }
        }

        public Statistics(string name, int? wins, int? loses, int? draws, string scores, int? points)
        {
            this.name = name;
            this.wins = wins;
            this.loses = loses;
            this.draws = draws;
            this.scores = scores;
            this.points = points;
        }
        public int CompareTo(Statistics statistics)
        {
            if (this.points < statistics.points)
            {
                return -1;
            }
             if (this.points > statistics.points)
            {
                return 1;
            }
            else
            {
                string[] current=this.scores.Split(':');
                string[] other=statistics.scores.Split(':');

                if ((int.Parse(current[1]) - int.Parse(current[0])) < (int.Parse(other[1]) - int.Parse(other[0])))
                {
                    return 1;
                }
                if ((int.Parse(current[1]) - int.Parse(current[0])) > (int.Parse(other[1]) - int.Parse(other[0])))
                {
                    return -1;
                }
                else
                {
                    if (string.Compare(this.name, statistics.name) == -1)
                    {
                        return 1;
                    }
                    if (string.Compare(this.name, statistics.name) == 1)
                    {
                        return -1;
                    }

                }
            }
             return 0;
        }

    }
}
